class Subscription {
  final String id;
  String name;
  String url;
  DateTime? lastUpdate;
  int serverCount;
  bool autoUpdate;
  int updateInterval; // in hours

  Subscription({
    required this.id,
    required this.name,
    required this.url,
    this.lastUpdate,
    this.serverCount = 0,
    this.autoUpdate = false,
    this.updateInterval = 24,
  });

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'url': url,
      'lastUpdate': lastUpdate?.toIso8601String(),
      'serverCount': serverCount,
      'autoUpdate': autoUpdate,
      'updateInterval': updateInterval,
    };
  }

  factory Subscription.fromJson(Map<String, dynamic> json) {
    return Subscription(
      id: json['id'],
      name: json['name'],
      url: json['url'],
      lastUpdate: json['lastUpdate'] != null ? DateTime.parse(json['lastUpdate']) : null,
      serverCount: json['serverCount'] ?? 0,
      autoUpdate: json['autoUpdate'] ?? false,
      updateInterval: json['updateInterval'] ?? 24,
    );
  }
}
